package edu.sjtu.search.controller;

import edu.sjtu.common.exception.BizCodeEnume;
import edu.sjtu.common.to.es.SkuEsModel;
import edu.sjtu.common.utils.R;
import edu.sjtu.search.service.ProductSaveService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RequestMapping("/search/save")
@RestController
public class ElasticSaveController {
    @Autowired
    ProductSaveService productSaveService;
    public R productStatusUp(@RequestBody List<SkuEsModel> skuEsModels) {

        boolean status =false;
        try {
            status = productSaveService.productStatusUp(skuEsModels);
        } catch (IOException e) {
          //  log.error("ElasticSaveController商品上架错误: {}", e);
            return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
        }
        if (!status) {
            return R.ok();
        }
        return R.error(BizCodeEnume.PRODUCT_UP_EXCEPTION.getCode(), BizCodeEnume.PRODUCT_UP_EXCEPTION.getMsg());
    }
}
